package com.enterprise.controller.api.common;

import com.enterprise.core.SystemManage;
import lombok.Data;

import java.io.Serializable;

@Data
public class BaseResponse<T> implements Serializable {

    private static final long serialVersionUID = -8844494281780273538L;
    private static final String httpstr = SystemManage.getInstance().getSystemSetting().getImageRootPath();
    public static String httpstr(String str){
        return httpstr+str;
    }

    private String code;
    private String msg;
    private T      data;

    public BaseResponse(){
        this.code = ResponseCode.SUCCESS.getCode();
        this.msg = ResponseCode.SUCCESS.getMsg();
        this.data = null;
    }


    public static <T> BaseResponse<T> success(T data) {
        BaseResponse<T> resp = new BaseResponse<T>();
        resp.setCode(ResponseCode.SUCCESS.getCode());
        resp.setMsg(ResponseCode.SUCCESS.getMsg());
        resp.setData(data);
        return resp;
    }

    public static <T> BaseResponse<T> success() {
        BaseResponse<T> resp = new BaseResponse<T>();
        resp.setCode(ResponseCode.SUCCESS.getCode());
        resp.setMsg(ResponseCode.SUCCESS.getMsg());
        return resp;
    }


    public static BaseResponse fail(String msg) {
        BaseResponse resp = new BaseResponse();
        resp.setCode(ResponseCode.FAIL.getCode());
        resp.setMsg(msg);
        return resp;
    }

    public static <T> BaseResponse<T> fail() {
        BaseResponse<T> resp = new BaseResponse<T>();
        resp.setCode(ResponseCode.SUCCESS.getCode());
        resp.setMsg(ResponseCode.SUCCESS.getMsg());
        return resp;
    }

}
